﻿@using Lib.core;
@using Lib.helper;

@using Bll;
@using WebLogic.Model.Page;
@{
    Layout = null;
    var list = ViewData["list"] as IList<SectionModel>;
    if (list == null)
    {
        list = new List<SectionModel>();
    }
}

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!-- header page -->
    @Html.Partial(IncludePath("header"))
</head>

<body>
    @Html.Partial(IncludePath("body_top"))
    @Html.Partial(IncludePath("manage_nav"))

    <div class="container-fluid">
        <div class="row">
            <div class="col-md-12">
                <div class="box sm right">
                    <a href="/admin/section/sectionedit/" class="btn btn-primary layer_win" target="_self">发布</a>
                </div>
            </div>
            <div class="col-md-12">
                <div class="panel panel-default">
                    <div class="panel-heading">页面</div>
                    <div class="panel-body">
                        @if (ValidateHelper.IsPlumpList(list))
                        {
                            <table class="table table-hover">
                                <thead>
                                    <tr>
                                        <td>ID</td>
                                        <td>名称</td>
                                        <td>标题</td>
                                        <td>描述</td>
                                        <td>类型</td>
                                        <td>关联组</td>
                                        <td>更新时间</td>
                                        <td>操作</td>
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach (var model in list)
                                    {
                                        <tr>
                                            <td>@(model.SectionID)</td>
                                            <td>
                                                <a href="/page/show/@(model.SectionName)/" target="_blank">@(model.SectionName)</a>
                                            </td>
                                            <td>@(model.SectionTitle)</td>
                                            <td>@(model.SectionDescription)</td>
                                            <td>@(model.SectionType)</td>
                                            <td>@(model.RelGroup)</td>
                                            <td>
                                                @(DateTimeHelper.GetFriendlyDateTime(model.UpdateTime))
                                            </td>
                                            <td>
                                                <a class="btn btn-default btn-sm layer_win" href="/admin/section/SectionEdit/?name=@(model.SectionName)" target="_blank">编辑</a>
                                                <button class="btn btn-sm btn-x del_btn" data-name="@(model.SectionName)">删除</button>
                                            </td>
                                        </tr>
                                    }
                                </tbody>
                            </table>
                            <div style="margin: 20px 0;">
                                @(Html.Raw(ViewData["pager"]))
                            </div>
                        }
                        else
                        {
                            <div class="alert alert-success">没有数据</div>
                        }
                    </div>
                </div>
            </div>
        </div>

        <script type="text/javascript">
            $(function () {
                $('.del_btn').click(function () {
                    if (!confirm('确定删除？')) {
                        return false;
                    }
                    var name = $(this).attr('data-name');
                    postJson('/admin/section/DeleteSectionAction/', { name: name }, function (res) {
                        if (res && res.success) {
                            alert('删除成功');
                            setTimeout(function () {
                                window.location.reload();
                            }, 2000);
                        }
                        else {
                            alert(res.msg);
                        }
                    });
                });
            });
        </script>

    </div>
    @Html.Partial(IncludePath("body_bottom"))
</body>
</html>
